package com.alibaba.controller;

import com.alibaba.bean.FollowInterface;
import com.alibaba.service.FollowInterfaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("isfollow")
public class FollowInterfaceController {
    @Autowired
    FollowInterfaceService followInterfaceService;

    @RequestMapping(value = "isfollow1", method = RequestMethod.POST)
    @ResponseBody
    public FollowInterface follow1(@RequestParam("toUserId") int toUserId, @RequestParam("userId") int userId, @RequestParam("isFollow") Boolean isFollow) {
        FollowInterface followInterface = new FollowInterface();
        boolean c = isFollow;
        if (c == true) {
            if (followInterfaceService.insert(toUserId,userId) == 1) {
                followInterface.setResult(true);
                followInterface.setErrorMsg("关注成功");
                followInterface.setData("");
            }
            else {
                followInterface.setResult(false);
                followInterface.setErrorMsg("关注失败");
                followInterface.setData("");
            }
            return followInterface;
        } else {
            if (followInterfaceService.delete(toUserId,userId) == 1) {
                followInterface.setResult(true);
                followInterface.setErrorMsg("取消关注成功");
                followInterface.setData("");
            }
            else  {
                followInterface.setResult(false);
                followInterface.setErrorMsg("取消关注失败");
                followInterface.setData("");
            }
            return followInterface;
        }
    }
}
